
public class Record {
	private String firstname,lastname,position;
	private int ID,delete;
	
	public Record(String FN,String LN, int num, String POS,int X){
		this.firstname = FN;
		this.lastname = LN;
		this.ID = num;
		this.position = POS;
		this.delete = X;
		
	}
	
	//Converts this record to string form
	public String toString(String valdelim, String fielddelim){
		String result = "FN" + valdelim  + firstname + fielddelim + "LN" + valdelim + lastname + fielddelim + "ID" + valdelim + ID
		+ fielddelim + "POS" + valdelim + position + fielddelim + "X" + valdelim + delete;
		return result;
	}
	
	//Returns ID
	public int getID(){
		return this.ID;
	}
	
	//Returns any field in the form of a string
	public String getInfoString(String fieldname){
		if(fieldname.equalsIgnoreCase("FirstName") || fieldname.equalsIgnoreCase("FN")){
			return this.firstname;
		}
		else if(fieldname.equalsIgnoreCase("LastName") || fieldname.equalsIgnoreCase("LN")){
			return this.lastname;
		}
		else if(fieldname.equalsIgnoreCase("ID")){
			return Integer.toString(this.ID);
		}
		else if(fieldname.equalsIgnoreCase("Position") || fieldname.equalsIgnoreCase("POS")){
			return this.position;
		}
		else if(fieldname.equalsIgnoreCase("Delete") || fieldname.equalsIgnoreCase("X")){
			return Integer.toString(this.delete);
		}
		else{
			throw new UnsupportedOperationException("Not supported");
		}
	}
	
	//Sets record to deleted
	public void setDelete(){
		this.delete = 1;
	}
	//Updates a field
	public void updateRecord(String fieldname,String value){
		if(fieldname.equalsIgnoreCase("FirstName") || fieldname.equalsIgnoreCase("FN")){
			this.firstname = value;
		}
		else if(fieldname.equals("LastName") || fieldname.equalsIgnoreCase("LN")){
			this.lastname = value;
		}
		else if(fieldname.equals("ID")){
			this.ID = Integer.parseInt(value);
		}
		else if(fieldname.equals("Position") || fieldname.equalsIgnoreCase("POS")){
			this.position = value;
		}
		else if(fieldname.equals("X") || fieldname.equalsIgnoreCase("DEL")){
			if(value.equals("1")){
				this.delete = 1;
			}
			else{
				this.delete = 0;
			}
		}
	}
	//Returns in boolean form whether this record is marked for deletion or not
	public boolean forDelete(){
		if(this.delete == 1){
			return true;
		}
		else{
			return false;
		}
	}
	
	//Extracts first name from whole record entry
	public static String parseFirstName(String input, String valdelim, String fielddelim){
		System.out.println("Parsing firstname");
		String delim = "FN" + valdelim;
		int firstnamepos = input.indexOf(delim) + delim.length();
		String firstname = "";
		while(firstnamepos < input.length() && input.charAt(firstnamepos) != fielddelim.charAt(0)){
			firstname = firstname + input.charAt(firstnamepos);
			firstnamepos++;
		}
		return firstname;
	}
	//Extracts last name from whole record entry
	public static String parseLastName(String input, String valdelim, String fielddelim){
		System.out.println("Parsing secondname");
		String delim = "LN" + valdelim;
		int lastnamepos = input.indexOf(delim) + delim.length();
		String lastname = "";
		while(lastnamepos < input.length() && input.charAt(lastnamepos) != fielddelim.charAt(0)){
			lastname = lastname + input.charAt(lastnamepos);
			lastnamepos++;
		}
		return lastname;		
	}
	//Extracts position from whole record entry
	public static String parsePosition(String input, String valdelim, String fielddelim){
		System.out.println("Parsing position");
		String delim = "POS" + valdelim;
		int positionpos = input.indexOf(delim) + delim.length();
		String position = "";
		while(positionpos < input.length() && input.charAt(positionpos) != fielddelim.charAt(0)){
			position = position + input.charAt(positionpos);
			positionpos++;
		}
		return position;				
	}
	//Extracts ID from whole record entry
	public static int parseID(String input, String valdelim, String fielddelim){
		System.out.println("Parsing ID");
		String delim = "ID" + valdelim;
		int idpos = input.indexOf(delim) + delim.length();
		String idstring = "";
		while(idpos < input.length() && input.charAt(idpos) != fielddelim.charAt(0)){
			idstring = idstring + input.charAt(idpos);
			idpos++;
		}
		int id = Integer.parseInt(idstring);
		return id;	
	}
	//Extracts deletion field from whole record entry
	public static int parseDel(String input, String valdelim){
		System.out.println("Parsing del");
		String delim = "X" + valdelim;
		int delpos = input.indexOf(delim) + delim.length();
		int del = input.charAt(delpos) - '0';
		return del;
	}
}
